<template>
    <div>
        <!-- 面包屑 -->
        <el-breadcrumb :separator-icon="ArrowRight">
            <el-breadcrumb-item :to="{ path: 'home' }">课程设计任务</el-breadcrumb-item>
            <el-breadcrumb-item>课程设计任务过程任务</el-breadcrumb-item>
            <el-breadcrumb-item>发布过程任务</el-breadcrumb-item>
        </el-breadcrumb>

        <h2 style="border-bottom: 1px solid;padding-bottom: 10px;">发布过程任务</h2>

        <div style="margin: 3% 5% 3% 5%;">
            <h1 style="margin: 10px;">详细信息</h1>

            <el-form :model="form" label-width="20%" size="large">
                <el-form-item label="题目名称">
                    <el-input v-model="coursePublish.processName" style="width: 200px;" />
                </el-form-item>
                <el-form-item label="班级">
                    <el-select v-model="coursePublish.practicalId" placeholder="选择班级">
                        <el-option v-for="item in classNum" :key="item.practicalId" :label="item.className"
                            :value="item.practicalId" />
                    </el-select>
                </el-form-item>
                <el-form-item label="实践时间">
                    <div class="block">
                        <el-date-picker style="" value-format="YYYY-MM-DD" v-model="taskTime" type="daterange"
                            range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" />
                    </div>
                </el-form-item>
                <el-form-item label="报告类型">
                    <el-radio-group v-model="coursePublish.processType" class="ml-4">
                        <el-radio label="0">过程任务</el-radio>
                        <el-radio label="1">最终报告</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="互评时间" v-if="coursePublish.processType == 1">
                    <div class="block">
                        <el-date-picker value-format="YYYY-MM-DD" v-model="scoreTime" type="daterange"
                            range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" />
                    </div>

                </el-form-item>
                <el-form-item label="实践内容">
                    <el-input v-model="coursePublish.content" type="textarea" style=" width: 50%;" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="publish">发布</el-button>
                    <el-button @click="toprocessTask">返回</el-button>
                </el-form-item>
            </el-form>
        </div>

    </div>
</template>
<script setup>
import { ref, onBeforeMount } from 'vue';
import { ArrowRight } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
import requests from '@/api/ajax';

onBeforeMount(() => {
    //获取班级和课程编号
    const aad = requests({ url: "/inner/courseClass", method: "get", }).then(res => {
        //存储用户信息到浏览器toke
        const abc = res.rdata
        classNum.value = abc
        // console.log(classNum.value)

    })
        .catch(err => {
            console.error(err.data);
            // 登录请求失败后的操作
        });
})

const classNum = ref([
    {

    }
])

//页面跳转到查看过程任务
const router_useRouter = useRouter()

function toprocessTask() {
    router_useRouter.push({ path: 'courseProTask' })
}
const coursePublish = ref({
    processName: '',
    practicalId: '',
    startDate: '',
    endDate: '',
    processType: '1',
    scoreStart: '',
    scoreEnd: '',
    content: ''
})

const taskTime = ref('')
const scoreTime = ref('')

function publish() {
    if (coursePublish.value.processType == 0) {
        coursePublish.value.startDate = taskTime.value[0]
        coursePublish.value.endDate = taskTime.value[1]

        coursePublish.value.scoreStart = taskTime.value[0]
        coursePublish.value.scoreEnd = taskTime.value[1]
    } else {
        coursePublish.value.startDate = taskTime.value[0]
        coursePublish.value.endDate = taskTime.value[1]

        coursePublish.value.scoreStart = scoreTime.value[0]
        coursePublish.value.scoreEnd = scoreTime.value[1]
    }

    const asd = requests({ url: "inner/processTask", method: "post", data: coursePublish.value }).then(res => {

        if (res.code === 20011) {
            alert(res.msg)
            router_useRouter.push({ path: 'courseProTask' })
        } else if (res.code === 20010) {
            alert(res.msg)
        }
    })
        .catch(err => {
            console.error(err.data);
            // 登录请求失败后的操作
        });
}
</script>